﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.Framework;
using CNVP.JShop.UI;
using CNVP.Framework.Utils;

namespace CNVP.JShop.Web.Admin
{
    public partial class LinksClassEdit : AdminPage
    {
        BLL.CNVP_Column bll = new BLL.CNVP_Column();
        Model.CNVP_Column model = new Model.CNVP_Column();
        public int id = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!BLL.BLLCheckAdmin.LoginOk(Page, 114)) return;//判断页面权限
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]) && Public.IsNumber(Request.QueryString["ID"]))
            {
                id = Convert.ToInt32(Request.QueryString["ID"]);
            }
            if (!IsPostBack)
            {
                if (id > 0)
                {
                    lbTitle.Text = " > 修改";
                    DataInfo(id);
                }
                else
                {
                    lbTitle.Text = " > 添加";
                }
            }
        }

        public void DataInfo(int id)
        {
            model = bll.GetSingle_CNVP_ColumnById(id);
            if (model != null)
            {
                txtColumnName.Text = model.ColumnName;
                rblIsShow.SelectedValue = model.IsShow.ToString();
                txtOrderID.Text = model.OrderID.ToString();
            }
        }

        protected void btUp_Click(object sender, EventArgs e)
        {
            if (txtColumnName.Text.Trim() == "")
            {
                BasePage.MessageBox("栏目名称不能为空！");
                txtColumnName.Focus();
                return;
            }
            if (id > 0)
            {
                int rows = new BLL.CNVP_Column().Update_CNVP_Column(
                       new Model.CNVP_Column()
                       {
                           ID = id,
                           ColumnName = txtColumnName.Text.Trim(),
                           ColumnType = (byte)1,
                           AddressRoute = "0",
                           Depth = "0",
                           IsShow = byte.Parse(rblIsShow.SelectedValue),
                           OrderID = int.Parse(txtOrderID.Text.Trim() == "" ? "0" : txtOrderID.Text.Trim()),
                           TemplateUrl ="2"
                       }

               );
                if (rows == 1)
                {
                    BasePage.MessageBox("修改成功！", "LinksClassList.aspx?Page=" + Request.QueryString["Page"] + "");
                }
                else
                { BasePage.MessageBox("修改失败！"); }
            }
            else
            {
                int rows = new BLL.CNVP_Column().Add_CNVP_Column(
                        new Model.CNVP_Column()
                        {
                            ColumnName = txtColumnName.Text.Trim(),
                            ColumnType = (byte)1,
                            AddressRoute = "0",
                            Depth = "0",
                            IsShow = byte.Parse(rblIsShow.SelectedValue),
                            OrderID = int.Parse(txtOrderID.Text.Trim() == "" ? "0" : txtOrderID.Text.Trim()),
                            TemplateUrl = "1"
                        }

                );
                if (rows > 0)
                {
                    BasePage.MessageBox("添加成功！", "LinksClassList.aspx");
                }
                else
                { BasePage.MessageBox("添加失败！"); }
            }
        }
    }
}